package io.renren.modules.lucky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.lucky.dao.AppSysFeedbackDao;
import io.renren.modules.lucky.entity.AppSysFeedbackEntity;
import io.renren.modules.lucky.service.AppSysFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service("appSysFeedbackService")
public class AppSysFeedbackServiceImpl extends ServiceImpl<AppSysFeedbackDao, AppSysFeedbackEntity> implements AppSysFeedbackService {

    @Autowired
    private AppSysFeedbackDao appSysFeedbackDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AppSysFeedbackEntity> page = this.page(
                new Query<AppSysFeedbackEntity>().getPage(params), new QueryWrapper<AppSysFeedbackEntity>()
        );
        return new PageUtils(page);
    }

    @Transactional(readOnly = false)
    public Map<String, Object> addFeedback(AppSysFeedbackEntity feedbackEntity) {
        Map<String, Object> map = new HashMap<>();
        feedbackEntity.setFeedbackFlag(1);
        feedbackEntity.setCreateTime(new Date());
        feedbackEntity.setUpdateTime(new Date());
        int num = appSysFeedbackDao.insert(feedbackEntity);
        map.put("flag", num);
        return map;
    }

}